#ifndef CHOOSEFRIENDDIALOG_H
#define CHOOSEFRIENDDIALOG_H

#include <QDialog>
#include <QWidget>
#include <QHBoxLayout>
#include <QScrollArea>
#include <QLineEdit>
#include <QCheckBox>
#include <QPushButton>
#include <QPaintEvent>
#include <QLabel>
#include "model/data.h"

/*----------------------- 选择好友 -----------------------*/
class ChooseFriendDialog : public QDialog
{
    Q_OBJECT
public:
    ChooseFriendDialog(QWidget* parent, const QString& userId, const QString& tipLabel);

    void initLeftPanel(QHBoxLayout* layout);
    void initRightPanel(QHBoxLayout* layout, const QString& tipLabel);
    void initScrollPanel(QVBoxLayout* layout, QWidget* &container);
    void initData();
    void clickOkBtn();
    QList<QString> generateMemberList();

    void addFriend(const QString& userId, const QIcon& avatar, const QString& name, bool checked);
    void addSelectedFriend(const QString& userId, const QIcon &avatar, const QString &name);
    void deleteSelectedFriend(const QString &userId);

private:
    QWidget* totalContainer; // 保存左侧全部好友列表的 QWidget
    QWidget* selectedContainer; // 保存右侧选中好友列表的 QWidget

    QString userId; // 当前选择窗口是点击哪个用户来弹出的.
};


/*----------------------- 选择好友窗口的元素 -----------------------*/
class ChooseFriendItem : public QWidget {
    Q_OBJECT
public:
    ChooseFriendItem(ChooseFriendDialog* owner, const QString& userId, const QIcon& avatar, const QString& name, bool checked);

    void paintEvent(QPaintEvent* event) override;
    void enterEvent(QEnterEvent* event) override;
    void leaveEvent(QEvent* event) override;

    const QString& getUserId() const {
        return userId;
    }

    QCheckBox* getCheckBox() {
        return checkBox;
    }

private:
    bool isHover = false;

    QCheckBox* checkBox;
    QPushButton* avatarBtn;
    QLabel* nameLabel;
    ChooseFriendDialog* owner;			// 记录了哪个 QWidget 持有了这个 Item. 此处的 QWidget 应该是一个 ChooseFriendDialog

    QString userId;   					// 记录了当前 Item 对应的 userId 是啥.
};


#endif // CHOOSEFRIENDDIALOG_H
